package com.sangu.dianxiu.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sangu.dianxiu.R;
import com.sangu.dianxiu.bean.order.OrderEntity;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 订单列表adapter，继承自AppBaseAdapter
 * Created by sg2 on 2015/12/25.
 */
public class OrderListAdapter extends AppBaseAdapter<OrderEntity.OrdersEntity>{
    public OrderListAdapter(List<OrderEntity.OrdersEntity> list, Context context) {
        super(list, context);
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        OrderEntity.OrdersEntity orderListEntity=list.get(position);
        ViewHolder vh=ViewHolder.get(context,convertView,parent, R.layout.item_order_list_layout);
        ImageView ivIcon= (ImageView) vh.findViewById(R.id.iv_item_order_list_icon);
        TextView tvName= (TextView) vh.findViewById(R.id.tv_item_order_list_name);
        TextView tvOrderTime= (TextView) vh.findViewById(R.id.tv_item_order_list_ordertime);
        TextView tvOrderNo= (TextView) vh.findViewById(R.id.tv_item_order_list_number);
        TextView tvRepairTime= (TextView) vh.findViewById(R.id.tv_item_order_list_repairtime);
        TextView tvMark= (TextView) vh.findViewById(R.id.tv_item_order_list_mark);
        ImageView ivQuality= (ImageView) vh.findViewById(R.id.iv_item_order_list_quality);
        if(!orderListEntity.isIsWarranty())
        {
            ivQuality.setVisibility(View.GONE);
        }
        tvName.setText(orderListEntity.getItems().get(0).getItemName());
        tvOrderTime.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(orderListEntity.getAddTime()));     //对毫秒数进行格式化
        tvRepairTime.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(orderListEntity.getOrderTime()));  //对毫秒数进行格式化
        tvOrderNo.setText(orderListEntity.getOrderNo());
        switch (orderListEntity.getStatus())            //根据不同的状态设置订单状态
        {
            case 0:
                tvMark.setText("已取消");
                break;
            case 1:
                tvMark.setText("报修中");
                break;
            case 2:
                tvMark.setText("已接单");
                break;
            case 3:
                tvMark.setText("待付款");
                break;
            case 4:
                tvMark.setText("已付款");
                break;
            case 5:
                tvMark.setText("已结算");
                break;
        }
        return vh;
    }
}
